import React, { Component } from 'react';
import { connect } from 'dva';
import { Modal, Form, Input, InputNumber } from 'antd';
const FormItem = Form.Item;

class AssetBrandModal extends Component {
  constructor(props) {
    super(props);
    this.state = {
      visible: false,
    };
  }

  showModelHandler = (e) => {
    if (e) e.stopPropagation();
    this.props.form.resetFields();
    this.setState({
      visible: true,
    });
  };

  hideModelHandler = () => {
    this.setState({
      visible: false,
    });
  };

  okHandler = () => {
    const { onOk } = this.props;
    this.props.form.validateFields((err, values) => {
      if (!err) {
        onOk(values);
        this.hideModelHandler();
      }
    });
  };

  render() {
    const { children,  title } = this.props;
    const { getFieldDecorator } = this.props.form;
    const { name,  remark } = this.props.record;
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 14 },
    };

    return (
        <span>
            <span onClick={this.showModelHandler}>
                { children }
            </span>
            <Modal
                confirmLoading={false}
                maskClosable={false}
                title={title}
                visible={this.state.visible}
                onOk={this.okHandler}
                onCancel={this.hideModelHandler}
            >
              <Form layout='horizontal' onSubmit={this.okHandler}>
                <FormItem
                  {...formItemLayout}
                  label="品牌名称"
                >
                  {
                    getFieldDecorator('name', {
                      initialValue: name,
                      rules: [{
                        required: true, whitespace: true, message: '请输入品牌名称',
                      },{
                        max: 50, whitespace: true, message: '品牌名称不能超过50个字',
                      }]
                    })(<Input />)
                  }
                </FormItem>
               
               <FormItem
                  {...formItemLayout}
                  label="备注"
                  hasFeedback
                >
                  {
                    getFieldDecorator('remark', {
                      initialValue: remark,
                      rules: [
                        { type: 'string', max: 100, message: '最多100个字符' }
                      ],
                    })(<Input type="textarea" rows={5} />)
                  }
                </FormItem>               
               
              </Form>
            </Modal> 
        </span>
    );
  }
}

export default Form.create()(AssetBrandModal);